/**
 * Created by Freeman on 2016/7/26.
 */
import {createStore,applyMiddleware,compose} from 'redux'
import thunk from 'redux-thunk'
import { routerMiddleware } from 'react-router-redux';
import api from '../api'
import rootReducer from '../reducers'

const configureStore = (initialState) => {

    //const store = (window.devToolsExtension ? window.devToolsExtension()(createStore) : createStore)(rootReducer, preloadedState,compose(applyMiddleware(thunk,api)));
    const store = createStore(
        rootReducer,
        initialState,
        compose(
            applyMiddleware(thunk,api, routerMiddleware(history)),
            window.devToolsExtension ? window.devToolsExtension() : f => f
        )
    );
    if (module.hot) {
        // Enable Webpack hot module replacement for reducers
        module.hot.accept('../reducers', () => {
            const nextReducer = require('../reducers').default
            store.replaceReducer(nextReducer)
        })
    }

    return store
};
export default configureStore;